package com.meritit.test;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.boot.actuate.endpoint.Endpoint;

public class MyEndPoint implements Endpoint{

	private List<MemStatus> status;
    public MyEndPoint(List<MemStatus> status) {
        this.status = status;
    }
	
	@Override
	public String getId() {
		return "my";
	}

	@Override
	public Object invoke() {
		if (status == null || status.isEmpty()) {
            return "hello world";
        }
        Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
        for (MemStatus memStatus : status) {
            for (Map.Entry<String, Object> entry : memStatus.getStatus().entrySet()) {
                List<Map<String, Object>> collectList = result.get(entry.getKey());
                if (collectList == null) {
                    collectList = new LinkedList<Map<String, Object>>();
                    result.put(entry.getKey(), collectList);
                }
                Map<String, Object> soloCollect = new HashMap<String, Object>();
                soloCollect.put("date", memStatus.getDate());
                soloCollect.put(entry.getKey(), entry.getValue());
                collectList.add(soloCollect);
            }
        }
        return result;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public boolean isSensitive() {
		return false;
	}

}
